package com.wangcang.widgetlibrary.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.pageindicator.MyFragmentPagerAdapter;
import com.wangcang.widgetlibrary.pageindicator.MyPageFragment;
import com.wangcang.widgetlibrary.pageindicator.SlideBarView;
import com.wangcang.widgetlibrary.viewindicator.CirclePageIndicator;
import com.wangcang.widgetlibrary.viewindicator.CustomViewPagerInternal;

import java.util.ArrayList;

public class DividerActivity extends FragmentActivity {
    CirclePageIndicator mIndicator = null;
    ArrayList<Fragment> fragmentArrayList = null;
    SlideBarView slideBarView = null;
    CustomViewPagerInternal viewPagerInternal;

    // 与SlideBarView结合的ViewPager
    ArrayList<Fragment> fragmentArrayList2 = null;
    CustomViewPagerInternal viewPagerInternal2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_divider);

        mIndicator = (CirclePageIndicator) findViewById(R.id.pager_indicator);
        viewPagerInternal = (CustomViewPagerInternal) findViewById(R.id.viewpager);
        viewPagerInternal2 = (CustomViewPagerInternal) findViewById(R.id.viewpager2);
        slideBarView = (SlideBarView) findViewById(R.id.slide_bar_view);

        fragmentArrayList = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            MyPageFragment fragment = new MyPageFragment();
            Bundle b = new Bundle();
            b.putInt("index", i);
            fragment.setArguments(b);
            fragmentArrayList.add(fragment);
        }

        MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragmentArrayList);
        viewPagerInternal.setAdapter(adapter);
        mIndicator.setViewPager(viewPagerInternal);


        // SideBarView
        fragmentArrayList2 = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            MyPageFragment fragment = new MyPageFragment();
            Bundle b = new Bundle();
            b.putInt("index", i);
            fragment.setArguments(b);
            fragmentArrayList2.add(fragment);
        }
        adapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragmentArrayList2);
        viewPagerInternal2.setAdapter(adapter);
        slideBarView.setOnSlideChange(new SlideBarView.OnSlideChange() {
            @Override
            public void onSlideChange(int page) {
                viewPagerInternal2.setCurrentItem(page);
            }
        });
        slideBarView.setViewPagerInternal(viewPagerInternal2);
    }
}
